// 表单验证方法
const validate = async (schema, body) => {
    let message = null
    try {
        /*验证*/
        await schema.validateAsync(body, { allowUnknown: true, abortEarly: true });
        message = null
    } catch (e) {
        message = e.message
    }
    return message
}
// 表单校验失败返回的code
const errorResponese = ({ res, code = "400", msg, data = null }) => {
    res.send({
        code,
        msg,
        data,
    })
}
// 成功的返回
const successResponese = ({ res, code = "200", msg = "成功", data = null }) => {
    res.send({
        code,
        msg,
        data,
    })
}

module.exports = {
    validate,
    errorResponese,
    successResponese
}